//This algorithm could be replaced by A* if needed
var graph = argument0;
var nodesPruned = 0;
var height = array_height_2d(graph) ;
var width = array_length_2d(graph, 0);
do
{
    nodesPruned = 0;
    for (var iii = 0; iii < height; iii++)
    {
        for (var jjj = 0; jjj < width; jjj++)
        {
            //middle pieces only
            if(is_real(graph[iii, jjj]) && graph[iii, jjj] > 0)
            {
                var exposures = 0;
                if (jjj + 1 < width && string(graph[iii, jjj + 1]) != '0')
                {
                    exposures++;
                }
                if (iii - 1 > -1 && string(graph[iii - 1, jjj]) != '0')
                {
                    exposures++;
                }
                if (jjj - 1 > -1 && string(graph[iii, jjj - 1]) != '0')
                {
                    exposures++;
                }
                if (iii + 1 < height && string(graph[iii + 1, jjj]) != '0')
                {
                    exposures++;
                }
                if (exposures == 1)
                {
                    graph[@ iii, jjj] = 0;
                    nodesPruned++;
                }
            }
        }
    }
} until (nodesPruned == 0);